package org.mc.service;

import io.swagger.annotations.ApiParam;
import org.mc.api.user.UserQueryServiceV1;
import org.mc.bean.UserCenterEntity;
import org.mc.common.data.PagedDTO;
import org.mc.common.data.ResultData;
import org.mc.common.util.BeanUtils;
import org.mc.domainservice.UserCenterDomainService;
import org.mc.response.user.CustomerDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserQueryRestServiceV1 implements UserQueryServiceV1 {

    @Autowired
    private UserCenterDomainService userCenterDomainService;

    @Override
    public ResultData<CustomerDTO> queryCustomer(@ApiParam(name = "userId", value = "用户id", required = true) @PathVariable("userId") Long userId) {
        UserCenterEntity userCenterEntity = userCenterDomainService.getUser(userId);
        CustomerDTO customerDTO = BeanUtils.convert(userCenterEntity, CustomerDTO.class);
        return ResultData.ok(customerDTO);
    }

    @Override
    public ResultData<PagedDTO<List<CustomerDTO>>> listAll(@ApiParam(value = "这是当前页数")
                                                           @RequestParam(value = "pageIndex", defaultValue = "0") int pageIndex,
                                                           @ApiParam(value = "这是每页条数")
                                                           @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        PagedDTO<List<CustomerDTO>> pagedDTO = userCenterDomainService.listAll(pageIndex, pageSize);
        return ResultData.ok(pagedDTO);
    }


}
